import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:lx_widgets_library/const/constant.dart';
import 'package:lx_widgets_library/r.dart';

///
/// 公共组件
///
class CommonWidgets {
  /// 标题栏 - 文字
  static Text navTitleText(String text, {Color? textColor, double? fontSize}) {
    return Text(
      text,
      style: TextStyle(
          color: textColor ?? const Color(0xFFD2D2D2),
          fontSize: fontSize ?? 17.0,
          fontWeight: FontWeight.w500),
    );
  }

  /// 标题
  static Text titleText(String text, {Color? textColor, double? fontSize}) {
    return Text(
      text,
      style: TextStyle(
          color: textColor ?? Colors.white.withOpacity(0.6),
          fontSize: fontSize ?? 14.0,
          fontWeight: FontWeight.w400),
    );
  }

  /// 副标题
  static Text subTitleText(String text, {Color? textColor, double? fontSize}) {
    return Text(
      text,
      style: TextStyle(
          color: textColor ?? Colors.white.withOpacity(0.6),
          fontSize: fontSize ?? 14.0,
          fontWeight: FontWeight.w400),
    );
  }

  /// 标题 value
  static Text valueText(String text, {Color? textColor, double? fontSize}) {
    return Text(
      text,
      style: TextStyle(
          color: textColor ?? Colors.white,
          fontSize: fontSize ?? 16.0,
          fontWeight: FontWeight.w400),
    );
  }

  /// 标题 hitText
  static Text placeholderText(String text,
      {Color? textColor, double? fontSize}) {
    return Text(
      text,
      style: TextStyle(
          color: textColor ?? Colors.white.withOpacity(0.4),
          fontSize: fontSize ?? 16.0,
          fontWeight: FontWeight.w400),
    );
  }

  /// 默认返回按钮
  static Widget appBarLeading({Color? color, void Function()? onTap}) {
    return IconButton(
      icon: Image.asset(
        LxR.nav_back_png,
        package: PACKAGE_NAME,
        width: 24,
      ),
      onPressed: () {
        if (onTap == null) {
          Get.back();
        } else {
          onTap();
        }
      },
    );
  }

  /// 列表箭头">"
  static Widget listArrow(
      {Color? color, double? size, void Function()? onTap}) {
    return IconButton(
      icon: Image.asset(
        LxR.item_arrow_png,
        package: PACKAGE_NAME,
        width: 24,
      ),
      onPressed: () => onTap,
    );
  }

  /// 标注 '*'
  static Text markText({Color? textColor, double? fontSize}) {
    return Text(
      '*',
      style: TextStyle(
        color: textColor ?? Colors.red.withOpacity(0.8),
        fontSize: fontSize ?? 14.0,
        fontWeight: FontWeight.w400,
      ),
    );
  }

  /// 空视图
  static Widget emptyView(String img, String title) {
    return Center(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          const SizedBox(height: 100),
          Image.asset(
            img,
            package: PACKAGE_NAME,
            width: 240,
            height: 240,
            fit: BoxFit.fitWidth,
          ),
          const SizedBox(width: 59),
          Text(
            title,
            style: TextStyle(
              color: Colors.white.withOpacity(0.6),
              fontSize: 12.0,
              fontWeight: FontWeight.w400,
            ),
          ),
        ],
      ),
    );
  }
}
